package guoan.service;

import guoan.domain.Words;
import guoan.domain.WordsConfig;
import guoan.repository.WordsConfigRepository;

import org.joda.time.DateTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional(readOnly = false)
public class WordjlsConfigService extends PageSerivce<WordsConfig> {
	protected final Logger log = LoggerFactory.getLogger(getClass());

	@Autowired
	private WordsConfigRepository wordsConfigRepository;

	public WordsConfig findOne(Long id) {
		// TODO Auto-generated method stub
		return wordsConfigRepository.findOne(id);
	}

	/**
	 * 保存信息,没有的话新建
	 * 
	 * @param adv
	 * @param path
	 */
	@Transactional(readOnly = false, rollbackFor = Exception.class)
	public void save(WordsConfig wordsConfig) {
		wordsConfigRepository.save(wordsConfig);
	}

	public WordsConfig initOne() {
		// TODO Auto-generated method stub
		WordsConfig wordsConfig = new WordsConfig();
		if (wordsConfigRepository.count() != 0l) {
			wordsConfig = wordsConfigRepository.findOne(1l);
		} else {
			wordsConfigRepository.save(wordsConfig);
		}
		return wordsConfig;
	}
}
